package com.x.cms.core.entity;

import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.SliceJpaObject;
import com.x.base.core.entity.annotation.ContainerEntity;
import com.x.base.core.project.annotation.FieldDescribe;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.*;

/**
 * 内容管理栏目配置支持信息
 * 
 * @author O2LEE
 *
 */
@ContainerEntity(dumpSize = 200, type = ContainerEntity.Type.content, reference = ContainerEntity.Reference.strong)
@Entity
@Table(name = PersistenceProperties.AppInfoConfig.table, uniqueConstraints = {
		@UniqueConstraint(name = PersistenceProperties.AppInfoConfig.table + JpaObject.IndexNameMiddle
				+ JpaObject.DefaultUniqueConstraintSuffix, columnNames = { JpaObject.IDCOLUMN,
						JpaObject.CREATETIMECOLUMN, JpaObject.UPDATETIMECOLUMN, JpaObject.SEQUENCECOLUMN }) })
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class AppInfoConfig extends SliceJpaObject {

	private static final long serialVersionUID = 3856138316794473794L;
	@SuppressWarnings("unused")
	private static final String TABLE = PersistenceProperties.AppInfoConfig.table;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@FieldDescribe("数据库主键,自动生成.")
	@Id
	@Column(length = length_id, name = ColumnNamePrefix + id_FIELDNAME)
	private String id = createId();

	public void onPersist() throws Exception {
	}
	/*
	 * =============================================================================
	 * ===== 以上为 JpaObject 默认字段
	 * =============================================================================
	 * =====
	 */

	/*
	 * =============================================================================
	 * ===== 以下为具体不同的业务及数据表字段要求
	 * =============================================================================
	 * =====
	 */
	public static final String config_FIELDNAME = "config";
	@FieldDescribe("配置支持信息JSON内容")
	@Lob
	@Basic(fetch = FetchType.EAGER)
	@Column(length = JpaObject.length_1M, name = ColumnNamePrefix + config_FIELDNAME)
	private String config;

	public String getConfig() {
		return StringUtils.isEmpty( config ) ? "{}" : config;
	}

	public void setConfig(String config) {
		this.config = config;
	}
}